/// <reference path="../typings/index.d.ts"/>
const API_PREFIX = "./bdpost/api/"
$(function () {
    $("#hujimiya").fullpage({
        css3: true,
        scrollingSpeed: 700,
        lazyLoading: false,
        // sectionsColor: ["rgba(255, 0, 0, 0.47)", "rgba(255, 0, 128, 0.49)", "rgb(130, 130, 255)"],
        navigation: true,
        controlArrows: false,
        anchors: ["about", "service", "concept", "main", "track"],
        normalScrollElements: ".tracks .details",//防止查看物流细节的时候翻页
        autoScrolling: true
    });

    /**
     * 填充物流搜索页的每一项
     * @param {String} content 
     * @param {String} datetime 
     */
    var tbRowItem = function (content, datetime) {
        return '<div class="tb-row"><div class="tb-meteor">&nbsp;</div>\
        <div class="tb-detail">'+ content + '<br>\
        '+ datetime + '</div>\
         </div>';
    };
    var input_for_track = $("input[name='track-no']");
    var details_wrapper = $("div.details");
    $(".track button[type='submit']").on("click", function (event) {
        var track_no = input_for_track.val();
        if (track_no.trim().length == 0) {
            return alert("请输入有效单号!");
        }
        $.get(API_PREFIX + track_no, function (res) {
            //eaxcp1750039
            if(res.status==1){
                //查询成功
                var tracks = res['track'].reverse();//由于
                var inner = "";//用于拼接html
                for(var i in tracks){
                    inner+=tbRowItem(tracks[i]['remark'],tracks[i]['time']);
                }
                details_wrapper.html(inner);
            }else{
                details_wrapper.html(res['tips']);
            }
        }, "jsonp");
    });
    $(".footer a.return").on("click",function(){
        location.hash="#about/main";
    });
    $("button.logistics-query").on("click",function(){
        location.hash="#about/track";
    })

});


